PCA Index Dashboard Examples¶

In [1]:
import pandas as pd
import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR

import warnings
warnings.filterwarnings("ignore")
In [2]:
now = pd.Timestamp.utcnow()
# convert now to central time 
print(f"This script was last run at {now} (UTC)")
print(f"In US/Central Time, this is {now.tz_convert('US/Central')}")

print("This line is Jonathan's modifications.")
This script was last run at 2024-03-03 20:52:35.243147+00:00 (UTC)
In US/Central Time, this is 2024-03-03 14:52:35.243147-06:00
This line is Jonathan's modifications.
In [3]:
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
In [4]:
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot();
No description has been provided for this image
In [5]:
# Simple version
fig = px.line(pc1)
fig.show()
In [6]:
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
In [7]:
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
No description has been provided for this image
In [8]:
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
In [9]:
pca_index.plot_unnormalized_series(df)
In [10]:
pca_index.plot_normalized_series(dfn)